package com.ruoyi.project.system.visitor.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.visitor.domain.JiaqinVisitor;
import com.ruoyi.project.system.visitor.service.IJiaqinVisitorService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 访客Controller
 * 
 * @author LCL
 * @date 2021-09-28
 */
@Controller
@RequestMapping("/system/visitor")
public class JiaqinVisitorController extends BaseController
{
    private String prefix = "system/visitor";

    @Autowired
    private IJiaqinVisitorService jiaqinVisitorService;

    @RequiresPermissions("system:visitor:view")
    @GetMapping()
    public String visitor()
    {
        return prefix + "/visitor";
    }

    /**
     * 查询访客列表
     */
    @RequiresPermissions("system:visitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinVisitor jiaqinVisitor)
    {
        startPage();
        List<JiaqinVisitor> list = jiaqinVisitorService.selectJiaqinVisitorList(jiaqinVisitor);
        return getDataTable(list);
    }

    /**
     * 导出访客列表
     */
    @RequiresPermissions("system:visitor:export")
    @Log(title = "访客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinVisitor jiaqinVisitor)
    {
        List<JiaqinVisitor> list = jiaqinVisitorService.selectJiaqinVisitorList(jiaqinVisitor);
        ExcelUtil<JiaqinVisitor> util = new ExcelUtil<JiaqinVisitor>(JiaqinVisitor.class);
        return util.exportExcel(list, "visitor");
    }

    /**
     * 新增访客
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存访客
     */
    @RequiresPermissions("system:visitor:add")
    @Log(title = "访客", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinVisitor jiaqinVisitor)
    {
        return toAjax(jiaqinVisitorService.insertJiaqinVisitor(jiaqinVisitor));
    }

    /**
     * 修改访客
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinVisitor jiaqinVisitor = jiaqinVisitorService.selectJiaqinVisitorById(id);
        mmap.put("jiaqinVisitor", jiaqinVisitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存访客
     */
    @RequiresPermissions("system:visitor:edit")
    @Log(title = "访客", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinVisitor jiaqinVisitor)
    {
        return toAjax(jiaqinVisitorService.updateJiaqinVisitor(jiaqinVisitor));
    }

    /**
     * 删除访客
     */
    @RequiresPermissions("system:visitor:remove")
    @Log(title = "访客", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinVisitorService.deleteJiaqinVisitorByIds(ids));
    }
}
